#!D:/CODE/python
# -*- coding: utf-8 -*-
# @Time : 2020/5/25 12:39
# @Author : Alexdong
# @Site : 
# @File : 迭代器斐波那契数列.py
# @Software: PyCharm
# Functional description:
from collections.abc import Iterable
from collections.abc import Iterator

class Fibonacci(object):
    def __init__(self, all_num):
        self.all_num = all_num
        self.current_num = 0
        self.a = 0
        self.b = 1

    def __iter__(self):
        """如果想要一个对象称为一个 可迭代的对象，就必须实现__iter__方法"""
        # 返回对象的引用
        return self   # 迭代器

    def __next__(self):
        if self.current_num < self.all_num:
            ret = self.a

            self.a, self.b = self.b, self.a+self.b
            self.current_num += 1
            return ret
        else:
            raise StopIteration

fibo = Fibonacci(10)

for num in fibo:
    print(num)
